﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BO = Viewer.BusinessObject.BusinessEntities;
using Ext.Net;
using System.IO;
using System.Text;
using Viewer.BusinessObject.BusinessEntities;
using System.Collections.Generic;
namespace Viewer.BaoCao
{
    public partial class BaoCaoCaNhan : System.Web.UI.Page
    {
        DataClassesDataContext db = new DataClassesDataContext();
        BO.CommonCode common = new Viewer.BusinessObject.BusinessEntities.CommonCode();
        BO.NSNhanVien nhanVien = new Viewer.BusinessObject.BusinessEntities.NSNhanVien();
        BO.NSToChuc query = new Viewer.BusinessObject.BusinessEntities.NSToChuc();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadControl();
                LoadDataForTree();
            }

        }
        [DirectMethod]
        public void LoadDataForTree()
        {
            //Load Root                     
            Ext.Net.TreeNode root = new Ext.Net.TreeNode("Tổ Chức Hành Chính");
            root.Expanded = true;
            root.CustomAttributes.Add(new ConfigItem("IsView", "0"));//disable
            root.Disabled = true;
            //root.Disabled = true;
            TreePanel.Root.Add(root);
            List<NSToChuc> lstToChuc = query.GetAll();
            List<NSToChuc> lstToChucLv1 = lstToChuc.Where(c => c.ToChucLevel == 1).ToList();

            foreach (var oToChucLv1 in lstToChucLv1)
            {
                var nodeLv1 = CreateNode(oToChucLv1);
                root.Nodes.Add(nodeLv1);
                List<NSToChuc> lstToChucLv2 = lstToChuc.Where(c => c.ToChucIDCha == oToChucLv1.ToChucID).ToList();
                foreach (var oToChucLv2 in lstToChucLv2)
                {
                    var nodeLv2 = CreateNode(oToChucLv2);
                    nodeLv1.Nodes.Add(nodeLv2);
                    List<NSToChuc> lstToChucLv3 = lstToChuc.Where(c => c.ToChucIDCha == oToChucLv2.ToChucID).ToList();
                    foreach (var oToChucLv3 in lstToChucLv3)
                    {
                        var nodeLv3 = CreateNode(oToChucLv3);
                        nodeLv2.Nodes.Add(nodeLv3);
                    }
                }
            }
            if (X.IsAjaxRequest)
            {
                Ext.Net.X.AddScript("refreshTree({0},{1});", TreePanel.ClientID, TreePanel.Root.ToJson());
            }
        }

        private List<QUNhomQuyenByToChuc_ToChuc> _nhomquyen;
        public List<QUNhomQuyenByToChuc_ToChuc> NhomQuyenByToChuc_ToChuc
        {
            get
            {
                if (_nhomquyen == null)
                {
                    //var oNguoidung = QUNguoiDung.GetByUserName(Page.User.Identity.Name.ToString());
                    //_nhomquyen = oNguoidung.NhomQuyenByToChuc_ToChuc();
                    _nhomquyen = (List<QUNhomQuyenByToChuc_ToChuc>)Session["NhomQuyenByToChuc_ToChuc"];
                }
                return _nhomquyen;
            }
        }

        /// <summary>
        /// Create TreeNode
        /// </summary>
        /// <param name="oToChuc"></param>
        /// <returns></returns>
        private Ext.Net.TreeNode CreateNode(NSToChuc oToChuc)
        {
            //Hard code for admin 
            if (Context.User.Identity.Name.ToLower() == "admin")
            {
                return CreateEnableNode(oToChuc, true, true, true, true);
            }
            bool IsView = false;
            bool IsAdd = false;
            bool IsEdit = false;
            bool IsDelete = false;

            //1 nguoi thuoc nhieu nhom quyen
            if (this.NhomQuyenByToChuc_ToChuc == null)
            {
                return CreateDisableNode(oToChuc.ToChucID.ToString(), oToChuc.TenToChucFull);
            }
            var lstNhomQuyenByToChuc_ToChuc = (from m in this.NhomQuyenByToChuc_ToChuc
                                               where m.ToChucID == oToChuc.ToChucID
                                               select m).ToList();
            if (lstNhomQuyenByToChuc_ToChuc.Count == 0)
            {
                //khong co quyen doi voi to chuc nay
                return CreateDisableNode(oToChuc.ToChucID.ToString(), oToChuc.TenToChucFull);
            }

            foreach (var item in lstNhomQuyenByToChuc_ToChuc)
            {
                IsView = IsView || item.IsView;
                IsAdd = IsAdd || item.IsAdd;
                IsEdit = IsEdit || item.IsEdit;
                IsDelete = IsDelete || item.IsDelete;
            }

            /////////////////
            if (!IsView)
            {
                return CreateDisableNode(oToChuc.ToChucID.ToString(), oToChuc.TenToChucFull);
            }
            return CreateEnableNode(oToChuc, IsView, IsAdd, IsEdit, IsDelete);
        }

        private Ext.Net.TreeNode CreateEnableNode(NSToChuc oToChuc, bool IsView, bool IsAdd, bool IsEdit, bool IsDelete)
        {
            Ext.Net.TreeNode node = new Ext.Net.TreeNode(oToChuc.ToChucID.ToString(), oToChuc.TenToChucFull, Icon.Group);
            node.CustomAttributes.Add(new ConfigItem("IsView", IsView ? "1" : "0"));
            node.CustomAttributes.Add(new ConfigItem("IsAdd", IsAdd ? "1" : "0"));
            node.CustomAttributes.Add(new ConfigItem("IsEdit", IsEdit ? "1" : "0"));
            node.CustomAttributes.Add(new ConfigItem("IsDelete", IsDelete ? "1" : "0"));

            node.Expanded = true;
            return node;
        }

        /// <summary>
        /// Create a disable treenode
        /// </summary>
        /// <param name="id"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        private Ext.Net.TreeNode CreateDisableNode(string id, string text)
        {
            Ext.Net.TreeNode node = new Ext.Net.TreeNode(id + "Decline", text, Icon.GroupKey);
            node.CustomAttributes.Add(new ConfigItem("IsView", "0"));
            node.Disabled = true;
            node.Cls = "Disable";
            node.Expanded = true;
            return node;
        }

        [DirectMethod]
        public void LoadGrid(string ID)
        {
            int id;
            try
            {
                id = int.Parse(ID);
            }
            catch (Exception)
            {

                id = 0;
            }
            hdIdCha.Text = id.ToString();
            storeNhanVien.DataSource = nhanVien.LoadAllGridByToChucId(id);
            storeNhanVien.DataBind();
            X.Mask.Hide();
        }
        protected void btnLookUpChoO_Click(object sender, DirectEventArgs e)
        {
            UCLookUpDiaChi.ShowDialogDiaChi();
        }
        protected void showPanel(object sender, DirectEventArgs e)
        {
            if (hdTimKiemNangCao.Value.Equals("0"))
            {
                CompositeField3.Hidden = true;
                hdTimKiemNangCao.Value = "1";
                CompositeField4.Hidden = true;
                lnlTimKiemNangCao.Text = "Tìm kiếm nâng cao";
            }
            else
            {
                CompositeField3.Hidden = false;
                hdTimKiemNangCao.Value = "0";
                CompositeField4.Hidden = false;
                lnlTimKiemNangCao.Text = "Tìm kiếm cơ bản";
            }
            X.Mask.Hide();
        }
        [DirectMethod]
        public void ClearData()
        {
            cbbToanTuCongTac.SelectedItem.Value = string.Empty;
            cbbToanTuVaoDang.SelectedItem.Value = string.Empty;
            hdChoOThuongTruSearchId.Value = string.Empty;
            txtNam.Text = string.Empty;
            txtNamVaoDang.Text = string.Empty;
            txtHoTen.Text = string.Empty;
            txtSoHieuCBCC.Text = string.Empty;
            txtSoCMND.Text = string.Empty;
            ckbTrangThaiNghiHuu.Checked = false;
            X.Mask.Hide();
        }
        protected void btnSearch_Click(object sender, DirectEventArgs e)
        {
            int idNode = !string.IsNullOrEmpty(hdNodeId.Text) ? Convert.ToInt16(hdNodeId.Text) : 0;
            int namCongTac = !string.IsNullOrEmpty(txtNam.Text) ? Convert.ToInt16(txtNam.Text) : 0;
            string toanTuCongTac = !string.IsNullOrEmpty(cbbToanTuCongTac.SelectedItem.Text) ? cbbToanTuCongTac.SelectedItem.Text : string.Empty;
            int namVaoDang = !string.IsNullOrEmpty(txtNam.Text) ? Convert.ToInt16(txtNam.Text) : 0;
            string toanTuVaoDang = !string.IsNullOrEmpty(cbbToanTuVaoDang.SelectedItem.Text) ? cbbToanTuVaoDang.SelectedItem.Text : string.Empty;
            int diaChi = !string.IsNullOrEmpty(hdChoOThuongTruSearchId.Value.ToString()) ? Convert.ToInt32(hdChoOThuongTruSearchId.Value) : 0;
            bool checkNghiHuu = ckbTrangThaiNghiHuu.Checked;
            storeNhanVien.DataSource = nhanVien.SearchByCondition(idNode, txtHoTen.Text, 0, 0, toanTuCongTac, namCongTac, toanTuVaoDang, namVaoDang, diaChi, checkNghiHuu, txtSoHieuCBCC.Text, txtSoCMND.Text);
            storeNhanVien.DataBind();
            X.Mask.Hide();
        }
        void LoadControl()
        {

            LoadNgheNghiepTuyenDung();

        }
        void LoadNgheNghiepTuyenDung()
        {
            string xmlFile = Server.MapPath("~/resources/DataCombobox_NgheNghiep.xml");
            DataSet ds = new DataSet();
            ds.ReadXml(xmlFile);
        }

        protected void btnLookUp_Click(object sender, DirectEventArgs e)
        {
            UcToChuc.ShowLookUp_ToChuc("", false, "");
        }
        protected void SelectNgheNghiep(object sender, DirectEventArgs e)
        {
        }

        protected void storeNhanVien_Submit(object sender, StoreSubmitDataEventArgs e)
        {
            //string fileName = "";
            //Response.Clear();
            //Response.AddHeader("Content-Type", "application/msword");
            //Response.AddHeader("Content-disposition","attachment; filename="+ fileName);
            //Export_SoYeuLyLich();
            string dataToExport = string.Empty;
            RowSelectionModel sm = (RowSelectionModel)GridPanel1.SelectionModel.Primary;
            int nhanvienId = int.Parse(sm.SelectedRow.RecordID);
            string fileName = string.Empty;
            var oNhanVien = new BO.NSNhanVien();
            oNhanVien = oNhanVien.GetById(nhanvienId);

            switch (__ReportType.Text)
            {
                case "SoYeuLyLich":
                    dataToExport = Export_SoYeuLyLich(nhanvienId);
                    fileName = "SoYeuLyLich_" + oNhanVien.HoTenKhaiSinh + ".doc";

                    break;
                case "QuaTrinhCongTacCaNhan":
                    dataToExport = Export_QuaTrinhCongTacCaNhan(nhanvienId);
                    fileName = "QuaTrinhCongTacCaNhan_" + oNhanVien.HoTenKhaiSinh + ".doc";

                    break;
                case "QuaTrinhNangBac":
                    dataToExport = Export_QuaTrinhNangBac(nhanvienId);
                    fileName = "QuaTrinhNangBac_" + oNhanVien.HoTenKhaiSinh + ".doc";

                    break;
                case "QuaTrinhCongTacDang":
                    dataToExport = Export_QuaTrinhCongTacDang(nhanvienId);
                    fileName = "QuaTrinhCongTacDang_" + oNhanVien.HoTenKhaiSinh + ".doc";

                    break;
            }
            if (dataToExport == string.Empty) return;

            Response.Clear();
            Response.AddHeader("Content-Type", "application/vnd.text");
            Response.ContentEncoding = Encoding.UTF8;
            Response.AddHeader("Content-disposition", "attachment; filename=" + fileName);
            Response.Write(dataToExport);
            Response.End();


        }
        private NSNgachBacLuong GetNgachCongChucMoiNhat(int nhanVienId)
        {

            var query = (from a in db.NSNgachBacLuongs
                         where a.NhanVienID.Equals(nhanVienId)
                         orderby a.NgayHieuLuc descending
                         select a).Take(1).SingleOrDefault();

            return query;
        }
        private NSQuaTrinhCongTac GetQuaTrinhCongTacMoiNhat(int nhanVienId)
        {

            var query = (from a in db.NSQuaTrinhCongTacs
                         where a.NhanVienId.Equals(nhanVienId)
                         orderby a.NgayBatDau descending
                         select a).Take(1).SingleOrDefault();

            return query;
        }
        private CHDiaChi GetDiaChi(int id)
        {
            var query = from a in db.CHDiaChis
                        where a.DiaChiID.Equals(id)
                        select a;
            return query.SingleOrDefault();
        }
        private string Export_SoYeuLyLich(int pNhanVienId)
        {
            string templatePath = Server.MapPath("Template/SoYeuLyLich.txt");
            if (!File.Exists(templatePath))
            {
                throw new Exception("Khong ton tai template");
            }
            string strData = string.Empty;

            using (StreamReader sr = File.OpenText(templatePath))
            {
                strData = sr.ReadToEnd();
            }
            var oNhanVien = new BO.NSNhanVien();
            oNhanVien = oNhanVien.GetById(pNhanVienId);
            if (oNhanVien != null)
            {
                NSNgachBacLuong ngachCongChuc = GetNgachCongChucMoiNhat(pNhanVienId);
                NSQuaTrinhCongTac quaTrinhCongTac = GetQuaTrinhCongTacMoiNhat(pNhanVienId);
                string str = "..............";
                string strDai = str + str + str + str + str;

                strData = strData.Replace("[HeSo]", ngachCongChuc != null && ngachCongChuc.HeSo > 0 ? ngachCongChuc.HeSo.ToString() : str);
                strData = strData.Replace("[TenNgach]", ngachCongChuc != null && !string.IsNullOrEmpty(ngachCongChuc.TenNgach) ? ngachCongChuc.TenNgach : str);
                strData = strData.Replace("[MaNgach]", ngachCongChuc != null && !string.IsNullOrEmpty(ngachCongChuc.MaNgach) ? ngachCongChuc.MaNgach : str);
                strData = strData.Replace("[BacLuong]", ngachCongChuc != null && ngachCongChuc.BacLuongID > 0 ? common.LoadCommonCodeById((int)ngachCongChuc.BacLuongID) : str);
                strData = strData.Replace("[NgayHuong]", ngachCongChuc != null ? ((DateTime)ngachCongChuc.NgayHieuLuc).ToString("dd/MM/yyyy") : str);
                strData = strData.Replace("[ChucVu]", str);
                strData = strData.Replace("[CongViecDuocGiao]", str);
                if (quaTrinhCongTac != null)
                {
                    strData = strData.Replace("[ChucVu]", !string.IsNullOrEmpty(quaTrinhCongTac.CongViec) ? quaTrinhCongTac.CongViec : str);
                    strData = strData.Replace("[CongViecDuocGiao]", !string.IsNullOrEmpty(quaTrinhCongTac.ChucVu) ? quaTrinhCongTac.ChucVu : str);
                }

                strData = strData.Replace("[HinhAnh]", Server.MapPath("~/Images/") + oNhanVien.Image);
                strData = strData.Replace("[SH]", !string.IsNullOrEmpty(oNhanVien.SoHieu) ? oNhanVien.SoHieu : str);
                strData = strData.Replace("[CQQL]", oNhanVien.CoQuanQuanLiId.Value > 0 ? query.LayTenToChuc(oNhanVien.CoQuanQuanLiId.Value) : str);
                strData = strData.Replace("[CQSD]", oNhanVien.CoQuanSuDungId.Value > 0 ? query.LayTenToChuc(oNhanVien.CoQuanSuDungId.Value) : str);
                strData = strData.Replace("[HoTenKhaiSinh]", oNhanVien.HoTenKhaiSinh);
                strData = strData.Replace("[TenGoiKhac]", !string.IsNullOrEmpty(oNhanVien.HoTenKhac) ? oNhanVien.HoTenKhac : str + str + str);
                strData = strData.Replace("[NgaySinh]", oNhanVien.NgaySinh.Day.ToString());
                strData = strData.Replace("[ThangSinh]", oNhanVien.NgaySinh.Month.ToString());
                strData = strData.Replace("[NamSinh]", oNhanVien.NgaySinh.Year.ToString());
                strData = strData.Replace("[GioiTinh]", !string.IsNullOrEmpty(common.LoadCommonCodeById(oNhanVien.GioiTinhID)) ? common.LoadCommonCodeById(oNhanVien.GioiTinhID) : str);
                strData = strData.Replace("[NoiSinh]", !string.IsNullOrEmpty(oNhanVien.DiaChiNoiSinh) ? oNhanVien.DiaChiNoiSinh : strDai);
                strData = strData.Replace("[XaQue]", GetDiaChi(oNhanVien.DiachiIDQueQuan) != null ? common.LoadTenHanhChinhById(GetDiaChi(oNhanVien.DiachiIDQueQuan).XaPhuongID) : str);
                strData = strData.Replace("[HuyenQue]", GetDiaChi(oNhanVien.DiachiIDQueQuan) != null ? common.LoadCommonCodeById(GetDiaChi(oNhanVien.DiachiIDQueQuan).QuanHuyenID) : str);
                strData = strData.Replace("[TinhQue]", GetDiaChi(oNhanVien.DiachiIDQueQuan) != null ? common.LoadCommonCodeById(GetDiaChi(oNhanVien.DiachiIDQueQuan).TinhTPID) : str);
                strData = strData.Replace("[ThuongBinhHang]", oNhanVien.HangThuongBinhID.Value > 0 ? common.LoadCommonCodeById(oNhanVien.HangThuongBinhID.Value) : str);
                strData = strData.Replace("[GDCS]", oNhanVien.ConGiaDinhChinhSachID.HasValue ? common.LoadCommonCodeById(oNhanVien.ConGiaDinhChinhSachID.Value) : str);
                strData = strData.Replace("[DanToc]", oNhanVien.DanTocID > 0 ? common.LoadCommonCodeById(oNhanVien.DanTocID) : str + str + str);
                strData = strData.Replace("[TonGiao]", oNhanVien.TonGiaoID > 0 ? common.LoadCommonCodeById(oNhanVien.TonGiaoID) : str + str + str);
                strData = strData.Replace("[HoKhauThuongTru]", GetDiaChi((int)oNhanVien.DiaChiIDHoKhau) != null ? common.LoadTenHanhChinhById(GetDiaChi((int)oNhanVien.DiaChiIDHoKhau).XaPhuongID) : str);

                strData = strData.Replace("[NoiOHienNay]", GetDiaChi((int)oNhanVien.DiaChiIDNoiOHienTai) != null ? common.LoadTenHanhChinhById(GetDiaChi((int)oNhanVien.DiaChiIDNoiOHienTai).XaPhuongID) : strDai);
                strData = strData.Replace("[NgayTuyenDung]", oNhanVien.NgayTuyenDung.HasValue ? oNhanVien.NgayTuyenDung.Value.ToString("dd/MM/yyyy") : str);
                strData = strData.Replace("[NgayCap]", oNhanVien.NgayCap != null ? ((DateTime)oNhanVien.NgayCap).ToString("dd/MM/yyyy") : string.Empty);
                strData = strData.Replace("[CMND]", !string.IsNullOrEmpty(oNhanVien.SoCMND) ? oNhanVien.SoCMND.ToString() : str + str);

                strData = strData.Replace("[CoQuanTD]", oNhanVien.ToChucIDTuyenDung > 0 ? query.LayTenToChuc((int)oNhanVien.ToChucIDTuyenDung) : strDai);
                strData = strData.Replace("[TDPT]", oNhanVien.TrinhDoGiaoDucPhoThongID.Value > 0 ? common.LoadCommonCodeById(oNhanVien.TrinhDoGiaoDucPhoThongID.Value) : str);
                strData = strData.Replace("[NgayVaoDang]", oNhanVien.NgayVaoDangCSVN.HasValue ? oNhanVien.NgayVaoDangCSVN.Value.ToString("dd/MM/yyyy") : str);
                strData = strData.Replace("[NgayChinhThuc]", oNhanVien.NgayChinhThucVaoDangCSVN.HasValue ? oNhanVien.NgayChinhThucVaoDangCSVN.Value.ToString("dd/MM/yyyy") : str);

                strData = strData.Replace("[NgayNhapNgu]", oNhanVien.NgayNhapNgu.HasValue ? oNhanVien.NgayNhapNgu.Value.ToString("dd/MM/yyyy") : str);
                strData = strData.Replace("[NgayXuatNgu]", oNhanVien.NgayXuatNgu.HasValue ? oNhanVien.NgayXuatNgu.Value.ToString("dd/MM/yyyy") : str);
                strData = strData.Replace("[QuanHamCaoNhat]", oNhanVien.QuanHamCaoNhatID.HasValue ? common.LoadCommonCodeById(oNhanVien.QuanHamCaoNhatID.Value) : str);
                strData = strData.Replace("[DHCN]", oNhanVien.DanhHieuCaoNhatID.HasValue ? common.LoadCommonCodeById(oNhanVien.DanhHieuCaoNhatID.Value) : str);

                strData = strData.Replace("[SotruongCongtac]", oNhanVien.SoTruongCongTac);
                strData = strData.Replace("[BHXH]", !string.IsNullOrEmpty(oNhanVien.SoBHXH) ? oNhanVien.SoBHXH : strDai);

                strData = strData.Replace("[TinhTrangSK]", oNhanVien.TinhTrangSucKhoe);
                strData = strData.Replace("[DHCN]", oNhanVien.DanhHieuCaoNhatID.Value > 0 ? common.LoadCommonCodeById(oNhanVien.DanhHieuCaoNhatID.Value) : str);
                strData = strData.Replace("[DHCN]", oNhanVien.DanhHieuCaoNhatID.Value > 0 ? common.LoadCommonCodeById(oNhanVien.DanhHieuCaoNhatID.Value) : str);

                strData = strData.Replace("[ChieuCao]", oNhanVien.ChieuCao.HasValue ? oNhanVien.ChieuCao.Value.ToString() : str);
                strData = strData.Replace("[CanNang]", oNhanVien.CanNang.HasValue ? oNhanVien.CanNang.Value.ToString() : str);
                strData = strData.Replace("[NhomMau]", oNhanVien.NhomMauID.HasValue ? common.LoadCommonCodeById(oNhanVien.NhomMauID.Value) : str);
                strData = strData.Replace("[KhenThuong]", ReturnTableData(pNhanVienId, "KT"));
                strData = strData.Replace("[KiLuat]", ReturnTableData(pNhanVienId, "KL"));
                strData = strData.Replace("[PCCV]", ReturnTableData(pNhanVienId, "PCCV"));
                strData = strData.Replace("[PCK]", ReturnTableData(pNhanVienId, "PCK"));
                strData = strData.Replace("[NgoaiNgu]", ReturnTableData(pNhanVienId, "NgoaiNgu"));
                strData = strData.Replace("[QTDT]", ReturnTableData(pNhanVienId, "QTDT"));
                strData = strData.Replace("[QTCT]", ReturnTableData(pNhanVienId, "QTCT"));
                strData = strData.Replace("[QHBT]", ReturnTableData(pNhanVienId, "QHBT"));
                strData = strData.Replace("[QH]", ReturnTableData(pNhanVienId, "QH"));
                strData = strData.Replace("[NX]", ReturnTableData(pNhanVienId, "NX"));
                strData = strData.Replace("[LSBT]", oNhanVien.LichSuChinhTri);
                strData = strData.Replace("[QuanHeTochucNuocNgoai]", oNhanVien.QuanHeToChucNuocNgoai);
                strData = strData.Replace("[QuanHeNhanThanNuocNgoai]", oNhanVien.QuanHeNhanThanNuocNgoai);
                strData = strData.Replace("[NCC]", ReturnTableData(pNhanVienId, "NCC"));
                strData = strData.Replace("[NgayThamGiaChinhTri]", oNhanVien.NgayVaoDangCSVN.HasValue ? ((DateTime)oNhanVien.NgayCap).ToString("dd/MM/yyyy") : strDai);
                strData = strData.Replace("[LBC]", ReturnTableData(pNhanVienId, "LBC"));
                strData = strData.Replace("[TDCN]", ReturnTableData(pNhanVienId, "TDCN"));
                strData = strData.Replace("[LLCT]", ReturnTableData(pNhanVienId, "LLCT"));
                strData = strData.Replace("[QLNN]", ReturnTableData(pNhanVienId, "QLNN"));
                strData = strData.Replace("[TinHoc]", ReturnTableData(pNhanVienId, "TinHoc"));
                strData = strData.Replace("[NgheNghiep]", ReturnTableData(pNhanVienId, "NgheNghiep"));
            }

            return strData;
        }
        private string ReturnTableData(int id, string type)
        {
            string str = string.Empty;
            string final = string.Empty;
            string mark = " - ";
            if (type.Equals("NgoaiNgu"))
            {


                var query = (from a in db.NSNgoaiNgus
                             where a.NhanVienID.Equals(id)
                             select a).ToList();

                foreach (NSNgoaiNgu item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.TenNgoaiNgu + "</td><td class=\"contentTD\">" + common.LoadCommonCodeById((int)item.TrinhDoNgoaiNguId) + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\" ><tr  ><td align=\"center\" class=\"border\">Tên ngoại ngữ</td><td align=\"center\" class=\"border\">Trình độ</td><td align=\"center\" class=\"border\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("KT"))
            {


                var query = (from a in db.NSKhenThuongs
                             where a.NhanVienID.Equals(id)
                             select a).ToList();

                foreach (NSKhenThuong item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.TenKhenThuong + "</td><td class=\"contentTD\">" + item.LoaiKhenThuong + "</td><td class=\"contentTD\">" + (item.NgayKhenThuong.HasValue ? ((DateTime)item.NgayKhenThuong).ToString("dd/MM/yyyy") : string.Empty) + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\" ><tr ><td class=\"border\" align=\"center\">Khen thưởng</td><td class=\"border\" align=\"center\">Nội dung</td><td class=\"border\" align=\"center\">Ngày khen thưởng</td><td class=\"border\" align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("KL"))
            {


                var query = (from a in db.NSKiLuats
                             where a.NhanVienId.Equals(id)
                             select a).ToList();

                foreach (NSKiLuat item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.TenKiLuat + "</td><td class=\"contentTD\">" + common.LoadCommonCodeById((int)item.CapKiLuatId) + "</td><td class=\"contentTD\">" + item.HinhThucKiLuat + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\" ><tr ><td class=\"border\" align=\"center\">Kỉ luật</td><td class=\"border\" align=\"center\">Cấp kỉ luật</td><td class=\"border\" align=\"center\">Nội dung</td><td class=\"border\" align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("PCCV"))
            {

                BO.NSPhuCapChucVu phucap = new NSPhuCapChucVu();
                List<NSPhuCapChucVu> query = phucap.LoadPCCVByNhanVienId(id);

                foreach (NSPhuCapChucVu item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.LoaiPhuCap + "</td><td class=\"contentTD\">" + item.HeSoPhuCap + "</td><td class=\"contentTD\">" + (item.NgayHieuLuc.HasValue ? ((DateTime)item.NgayHieuLuc).ToString("dd/MM/yyyy") : string.Empty) + "</td><td class=\"contentTD\">" + item.NgayHetHieuLuc.Value.ToString("dd/MM/yyyy") + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\" class=\"border\"><tr ><td class=\"border\" align=\"center\">Loại phụ cấp</td><td class=\"border\" align=\"center\">Hệ số</td><td class=\"border\" align=\"center\">Ngày hiệu lực</td><td class=\"border\" align=\"center\">Ngày hết hiệu lực</td><td class=\"border\" align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("PCK"))
            {

                BO.NSPhuCapKhac phucap = new NSPhuCapKhac();
                List<NSPhuCapKhac> query = phucap.LoadPCKByNhanVienId(id);

                foreach (NSPhuCapKhac item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.LoaiPhuCapKhac + "</td><td class=\"contentTD\">" + item.HeSoPhuCap + "</td><td class=\"contentTD\">" + item.NgayHieuLuc.ToString("dd/MM/yyyy") + "</td><td class=\"contentTD\">" + item.NgayHetHieuLuc.Value.ToString("dd/MM/yyyy") + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\" ><tr><td class=\"border\" align=\"center\">Loại phụ cấp</td><td class=\"border\" align=\"center\">Hệ số</td><td class=\"border\" align=\"center\">Ngày hiệu lực</td><td class=\"border\" align=\"center\">Ngày hết hiệu lực</td><td class=\"border\" align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("QTDT"))
            {

                BO.NSDaoTao phucap = new NSDaoTao();
                List<NSDaoTao> query = phucap.LoadDTByNhanVienId(id);

                foreach (NSDaoTao item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.TenTruong + "</td><td class=\"contentTD\">" + item.ChuyenNganhDaoTao + "</td><td class=\"contentTD\">" + item.NgayBatDau.ToString("dd/MM/yyyy") + "-" + item.NgayKetThuc.ToString("dd/MM/yyyy") + "</td><td class=\"contentTD\">" + item.TenHinhThuc + "</td><td class=\"contentTD\">" + item.VanBang + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\" class=\"border\"><tr ><td class=\"border\" align=\"center\">Tên trường</td><td class=\"border\" align=\"center\">Chuyên ngành đào tạo, bồi dưỡng</td><td class=\"border\" align=\"center\">Từ ngày - đến ngày</td><td class=\"border\" align=\"center\">Hình thức đào tạo</td><td class=\"border\" align=\"center\">Văn bằng, chứng chỉ, trình độ gì</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("QTCT"))
            {

                BO.NSQuaTrinhCongTac qtct = new NSQuaTrinhCongTac();
                List<NSQuaTrinhCongTac> query = qtct.LoadQTCTByNhanVienId(id);

                foreach (NSQuaTrinhCongTac item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + (item.NgayBatDau.HasValue ? item.NgayBatDau.Value.ToString("dd/MM/yyyy") : string.Empty) + "-" + (item.NgayKetThuc.HasValue ? item.NgayKetThuc.Value.ToString("dd/MM/yyyy") : string.Empty) + "</td><td class=\"contentTD\">" + item.TenCoQuan + "</td><td class=\"contentTD\">" + item.CongViec + "</td><td class=\"contentTD\">" + item.ChucVu + "</td><td class=\"contentTD\">" + item.NoiDung + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\" ><tr ><td class=\"border\" align=\"center\">Từ ngày - đến ngày</td><td class=\"border\" align=\"center\">Tên cơ quan</td><td class=\"border\" align=\"center\">Công việc</td><td class=\"border\" align=\"center\">Chức vụ</td><td class=\"border\" align=\"center\">Nội dung</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("QuaTrinhCongTacDang"))
            {

                BO.NSQuaTrinhCongTacDang quaTrinhCongTacDang = new NSQuaTrinhCongTacDang();
                List<NSQuaTrinhCongTacDang> query = quaTrinhCongTacDang.LoadQTCTDangByNhanVienId(id);

                foreach (NSQuaTrinhCongTacDang item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + (item.NgayNhanXet.HasValue ? item.NgayNhanXet.Value.ToString("dd/MM/yyyy") : string.Empty) + "</td><td class=\"contentTD\">" + item.ChiBoDang + "</td><td class=\"contentTD\">" + item.NoiDungNhanXet + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\" ><tr ><td class=\"border\" align=\"center\">Ngày nhận xét</td><td class=\"border\" align=\"center\">Chi bộ Đảng</td><td class=\"border\" align=\"center\">Nội dung</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("QHBT"))
            {

                BO.NSQuanHeGiaDinh qtct = new NSQuanHeGiaDinh();
                List<NSQuanHeGiaDinh> query = qtct.LoadQHByNhanVienId(id, "QHBT");

                foreach (NSQuanHeGiaDinh item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.TenMoiQuanHe + "</td><td class=\"contentTD\">" + item.HoTenNguoiQuanHe + "</td><td class=\"contentTD\">" + (item.NamSinh.HasValue ? ((DateTime)item.NamSinh).ToString("dd/MM/yyyy") : string.Empty) + "</td><td class=\"contentTD\">" + item.LyLich + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\" ><tr><td class=\"border\"  align=\"center\">Mối quan hệ</td><td class=\"border\"  align=\"center\">Họ và tên</td><td  class=\"border\"   align=\"center\">Ngày sinh</td><td  class=\"border\" align=\"center\">Quê quán nghề nghiệp, chức danh, chức vụ, đơn vị công tác, học tập nơi ở(trong, ngoài nước); thành viên các tổ chức chính trị xã hội</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("QH"))
            {

                BO.NSQuanHeGiaDinh qtct = new NSQuanHeGiaDinh();
                List<NSQuanHeGiaDinh> query = qtct.LoadQHByNhanVienId(id, "QH");

                foreach (NSQuanHeGiaDinh item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.TenMoiQuanHe + "</td><td class=\"contentTD\">" + item.HoTenNguoiQuanHe + "</td><td class=\"contentTD\">" + (item.NamSinh.HasValue ? ((DateTime)item.NamSinh).ToString("dd/MM/yyyy") : string.Empty) + "</td><td class=\"contentTD\">" + item.LyLich + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td  class=\"border\" align=\"center\">Mối quan hệ</td><td  class=\"border\" align=\"center\">Họ và tên</td><td  class=\"border\" align=\"center\">Ngày sinh</td><td  class=\"border\" align=\"center\">Quê quán nghề nghiệp, chức danh, chức vụ, đơn vị công tác, học tập nơi ở(trong, ngoài nước); thành viên các tổ chức chính trị xã hội</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("NX"))
            {

                BO.NSNhanXet qtct = new NSNhanXet();
                List<NSNhanXet> query = qtct.LoadNXByNhanVienId(id);

                foreach (NSNhanXet item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + (item.NgayThangNhanXet.HasValue ? ((DateTime)item.NgayThangNhanXet).ToString("dd/MM/yyyy") : string.Empty) + "</td><td class=\"contentTD\">" + item.NoiDung + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"70px\"  align=\"center\">Ngày</td><td class=\"border\"  align=\"center\">Lý lịch</td></tr>" + str + "</table>";
                return final;
            }

            //else if (type.Equals("CongViecDuocGiao"))
            //{

            //    BO.NSCongViecChinh qtct = new NSCongViecChinh();
            //    List<NSCongViecChinh> query = qtct.LoadCongViecChinhByNhanVienId(id);

            //    foreach (NSCongViecChinh item in query)
            //    {
            //        str = str + "<tr><td class=\"contentTD\">" + item.Ten + "</td><td class=\"contentTD\">" + item.ThoiGianThayDoi.ToString("dd/MM/yyyy") + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
            //    }

            //    final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"100px\"  align=\"center\">Công việc</td><td class=\"border\" width=\"70px\"  align=\"center\">Ngày</td><td class=\"border\"  align=\"center\">Lý lịch</td></tr>" + str + "</table>";
            //    return final;
            //}
            else if (type.Equals("NgheNghiep"))
            {

                BO.NSNgheNghiep qtct = new NSNgheNghiep();
                List<NSNgheNghiep> query = qtct.LoadNgheNghiepByNhanVienId(id);

                foreach (NSNgheNghiep item in query)
                {
                    string ngayKetThuc = item.NgayKetThuc.HasValue ? mark + item.NgayKetThuc.Value.ToString("dd/MM/yyyy") : string.Empty;
                    str = str + "<tr><td class=\"contentTD\">" + item.TenNghe + "</td><td class=\"contentTD\">" + (item.NgayBatDau.Value.ToString("dd/MM/yyyy")) + (ngayKetThuc) + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"100px\"  align=\"center\">Nghề nghiệp</td><td class=\"border\" width=\"70px\"  align=\"center\">Ngày</td><td class=\"border\"  align=\"center\">Lý lịch</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("HDLD"))
            {

                BO.NSHopDongLaoDong qtct = new NSHopDongLaoDong();
                List<NSHopDongLaoDong> query = qtct.LoadHDLDByNhanVienId(id);

                foreach (NSHopDongLaoDong item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.TenHopDongLaoDong + "</td><td class=\"contentTD\">" + item.NgayHieuLuc.ToString("dd/MM/yyyy") + "</td><td class=\"contentTD\">" + item.NgayHetHieuLuc.Value.ToString("dd/MM/yyyy") + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"100px\"  align=\"center\">Tên hợp đồng</td><td class=\"border\"  align=\"center\">Ngày hiệu lực</td><td class=\"border\"  align=\"center\">Ngày hết hiệu lực</td><td class=\"border\"  align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("NCC"))
            {

                BO.NSNgachBacLuong qtct = new NSNgachBacLuong();
                List<NSNgachBacLuong> query = qtct.LoadNBLByNhanVienId(id);

                foreach (NSNgachBacLuong item in query)
                {
                    str = str + "<tr><td class=\"contentTD\">" + item.TenNgach + "</td><td class=\"contentTD\">" + item.MaNgach + "</td><td class=\"contentTD\">" + item.TenHeSo + "</td><td class=\"contentTD\">" + item.TenBacLuong + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"100px\"  align=\"center\">Ngạch công chức</td><td class=\"border\" width=\"100px\"  align=\"center\">Mã ngạch</td><td class=\"border\" width=\"100px\"  align=\"center\">Hệ số</td><td class=\"border\" width=\"100px\"  align=\"center\">Bậc lương</td><td class=\"border\"  align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("LBC"))
            {

                BO.NSBangCap bc = new NSBangCap();
                List<NSBangCap> query = bc.LoadData(id);

                foreach (NSBangCap item in query)
                {
                    string ngayHieuLuc = item.NgayHieuLuc.HasValue ? mark + item.NgayHieuLuc.Value.ToString("dd/MM/yyyy") : string.Empty;
                    str = str + "<tr><td class=\"contentTD\">" + item.TenBangCap + "</td><td class=\"contentTD\">" + ngayHieuLuc + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"100px\"  align=\"center\">Bằng cấp</td><td class=\"border\" width=\"100px\"  align=\"center\">Ngày hiệu lực</td><td class=\"border\"  align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("TDCN"))
            {

                BO.NSTrinhDoChuyenMon bc = new NSTrinhDoChuyenMon();
                List<NSTrinhDoChuyenMon> query = bc.LoadTDCMByNhanVienId(id);

                foreach (NSTrinhDoChuyenMon item in query)
                {
                    string ngayHieuLuc = item.NgayHieuLuc.HasValue ? mark + item.NgayHieuLuc.Value.ToString("dd/MM/yyyy") : string.Empty;
                    str = str + "<tr><td class=\"contentTD\">" + item.TenTrinhDoChuyenMon + "</td><td class=\"contentTD\">" + ngayHieuLuc + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"100px\"  align=\"center\">Chuyên môn</td><td class=\"border\" width=\"100px\"  align=\"center\">Ngày hiệu lực</td><td class=\"border\"  align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("LLCT"))
            {

                BO.NSLiLuanChinhTri bc = new NSLiLuanChinhTri();
                List<NSLiLuanChinhTri> query = bc.LoadData(id);

                foreach (NSLiLuanChinhTri item in query)
                {
                    string ngayHieuLuc = item.NgayHieuLuc.HasValue ? mark + item.NgayHieuLuc.Value.ToString("dd/MM/yyyy") : string.Empty;
                    str = str + "<tr><td class=\"contentTD\">" + item.TenLiLuanChinhTri + "</td><td class=\"contentTD\">" + ngayHieuLuc + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"100px\"  align=\"center\">Tên lí luận</td><td class=\"border\" width=\"100px\"  align=\"center\">Ngày hiệu lực</td><td class=\"border\"  align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("QLNN"))
            {

                BO.NSQuanLiNhaNuoc bc = new NSQuanLiNhaNuoc();
                List<NSQuanLiNhaNuoc> query = bc.LoadData(id);

                foreach (NSQuanLiNhaNuoc item in query)
                {
                    string ngayHieuLuc = item.NgayHieuLuc.HasValue ? mark + item.NgayHieuLuc.Value.ToString("dd/MM/yyyy") : string.Empty;
                    str = str + "<tr><td class=\"contentTD\">" + item.TenLoaiQuanLiNhaNuoc + "</td><td class=\"contentTD\">" + ngayHieuLuc + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"100px\"  align=\"center\">Loại</td><td class=\"border\" width=\"100px\"  align=\"center\">Ngày hiệu lực</td><td class=\"border\"  align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            else if (type.Equals("TinHoc"))
            {

                BO.NSTrinhDoTinHoc bc = new NSTrinhDoTinHoc();
                List<NSTrinhDoTinHoc> query = bc.LoadData(id);

                foreach (NSTrinhDoTinHoc item in query)
                {
                    string ngayHieuLuc = item.NgayHieuLuc.HasValue ? mark + item.NgayHieuLuc.Value.ToString("dd/MM/yyyy") : string.Empty;
                    str = str + "<tr><td class=\"contentTD\">" + item.TenTrinhDoTinHoc + "</td><td class=\"contentTD\">" + ngayHieuLuc + "</td><td class=\"contentTD\">" + item.GhiChu + "</td></tr>";
                }

                final = "<table border=1 style=\"border-color:Black\" width=\"100%\" cellpadding=0 cellspacing=0 align=\"center\"  ><tr  ><td class=\"border\" width=\"100px\"  align=\"center\">Trình độ</td><td class=\"border\" width=\"100px\"  align=\"center\">Ngày hiệu lực</td><td class=\"border\"  align=\"center\">Ghi chú</td></tr>" + str + "</table>";
                return final;
            }
            return string.Empty;
        }
        private string Export_QuaTrinhCongTacCaNhan(int pNhanVienId)
        {
            string str = "..............";
            string strDai = str + str + str + str + str + str;
            string templatePath = Server.MapPath("Template/QuaTrinhCongTac.txt");
            if (!File.Exists(templatePath))
            {
                throw new Exception("Khong ton tai template");
            }
            string strData = string.Empty;

            using (StreamReader sr = File.OpenText(templatePath))
            {
                strData = sr.ReadToEnd();
            }
            var oNhanVien = new BO.NSNhanVien();
            oNhanVien = oNhanVien.GetById(pNhanVienId);
            if (oNhanVien != null)
            {
                strData = strData.Replace("[SoHieu]", !string.IsNullOrEmpty(oNhanVien.SoHieu) ? oNhanVien.SoHieu : str);
                strData = strData.Replace("[CQQL]", oNhanVien.CoQuanQuanLiId.Value > 0 ? query.LayTenToChuc(oNhanVien.CoQuanQuanLiId.Value) : str);
                strData = strData.Replace("[CQSD]", oNhanVien.CoQuanSuDungId.Value > 0 ? common.LoadCommonCodeById(oNhanVien.CoQuanSuDungId.Value) : str);
                strData = strData.Replace("[HoTenKhaiSinh]", oNhanVien.HoTenKhaiSinh);
                strData = strData.Replace("[NgaySinh]", oNhanVien.NgaySinh.Day.ToString());
                strData = strData.Replace("[ThangSinh]", oNhanVien.NgaySinh.Month.ToString());
                strData = strData.Replace("[NamSinh]", oNhanVien.NgaySinh.Year.ToString());
                strData = strData.Replace("[GioiTinh]", !string.IsNullOrEmpty(common.LoadCommonCodeById(oNhanVien.GioiTinhID)) ? common.LoadCommonCodeById(oNhanVien.GioiTinhID) : str);
                strData = strData.Replace("[CMND]", !string.IsNullOrEmpty(oNhanVien.SoCMND) ? oNhanVien.SoCMND.ToString() : strDai);
                strData = strData.Replace("[QTCT]", ReturnTableData(pNhanVienId, "QTCT"));
                strData = strData.Replace("[KT]", ReturnTableData(pNhanVienId, "KT"));
                strData = strData.Replace("[KL]", ReturnTableData(pNhanVienId, "KL"));
                strData = strData.Replace("[NX]", ReturnTableData(pNhanVienId, "NX"));
            }
            return strData;
        }

        private string Export_QuaTrinhCongTacDang(int pNhanVienId)
        {
            string str = "..............";
            string strDai = str + str + str + str + str + str;
            string templatePath = Server.MapPath("Template/QuaTrinhCongTacDang.txt");
            if (!File.Exists(templatePath))
            {
                throw new Exception("Không tồn tại template");
            }
            string strData = string.Empty;

            using (StreamReader sr = File.OpenText(templatePath))
            {
                strData = sr.ReadToEnd();
            }
            var oNhanVien = new BO.NSNhanVien();
            oNhanVien = oNhanVien.GetById(pNhanVienId);
            if (oNhanVien != null)
            {
                strData = strData.Replace("[SoHieu]", !string.IsNullOrEmpty(oNhanVien.SoHieu) ? oNhanVien.SoHieu : str);
                strData = strData.Replace("[CQQL]", oNhanVien.CoQuanQuanLiId.Value > 0 ? query.LayTenToChuc(oNhanVien.CoQuanQuanLiId.Value) : str);
                strData = strData.Replace("[CQSD]", oNhanVien.CoQuanSuDungId.Value > 0 ? common.LoadCommonCodeById(oNhanVien.CoQuanSuDungId.Value) : str);
                strData = strData.Replace("[HoTenKhaiSinh]", oNhanVien.HoTenKhaiSinh);
                strData = strData.Replace("[NgaySinh]", oNhanVien.NgaySinh.Day.ToString());
                strData = strData.Replace("[ThangSinh]", oNhanVien.NgaySinh.Month.ToString());
                strData = strData.Replace("[NamSinh]", oNhanVien.NgaySinh.Year.ToString());
                strData = strData.Replace("[GioiTinh]", !string.IsNullOrEmpty(common.LoadCommonCodeById(oNhanVien.GioiTinhID)) ? common.LoadCommonCodeById(oNhanVien.GioiTinhID) : str);
                strData = strData.Replace("[CMND]", !string.IsNullOrEmpty(oNhanVien.SoCMND) ? oNhanVien.SoCMND.ToString() : strDai);
                strData = strData.Replace("[QuaTrinhCongTacDang]", ReturnTableData(pNhanVienId, "QuaTrinhCongTacDang"));
                strData = strData.Replace("[NgayVaoDang]", oNhanVien.NgayVaoDangCSVN.HasValue ? oNhanVien.NgayVaoDangCSVN.Value.ToString("dd/MM/yyyy") : str);
                strData = strData.Replace("[NgayChinhThuc]", oNhanVien.NgayChinhThucVaoDangCSVN.HasValue ? oNhanVien.NgayChinhThucVaoDangCSVN.Value.ToString("dd/MM/yyyy") : str);
            }
            return strData;
        }

        private string Export_QuaTrinhNangBac(int pNhanVienId)
        {
            string str = "..............";
            string strDai = str + str + str + str + str + str;
            string templatePath = Server.MapPath("Template/QuaTrinhNangBac.txt");
            if (!File.Exists(templatePath))
            {
                throw new Exception("Khong ton tai template");
            }
            string strData = string.Empty;

            using (StreamReader sr = File.OpenText(templatePath))
            {
                strData = sr.ReadToEnd();
            }
            var oNhanVien = new BO.NSNhanVien();
            oNhanVien = oNhanVien.GetById(pNhanVienId);
            if (oNhanVien != null)
            {
                strData = strData.Replace("[SoHieu]", !string.IsNullOrEmpty(oNhanVien.SoHieu) ? oNhanVien.SoHieu : str);
                strData = strData.Replace("[CQQL]", oNhanVien.CoQuanQuanLiId.Value > 0 ? query.LayTenToChuc(oNhanVien.CoQuanQuanLiId.Value) : str);
                strData = strData.Replace("[CQSD]", oNhanVien.CoQuanSuDungId.Value > 0 ? common.LoadCommonCodeById(oNhanVien.CoQuanSuDungId.Value) : str);
                strData = strData.Replace("[HoTenKhaiSinh]", oNhanVien.HoTenKhaiSinh);
                strData = strData.Replace("[NgaySinh]", oNhanVien.NgaySinh.Day.ToString());
                strData = strData.Replace("[ThangSinh]", oNhanVien.NgaySinh.Month.ToString());
                strData = strData.Replace("[NamSinh]", oNhanVien.NgaySinh.Year.ToString());
                strData = strData.Replace("[GioiTinh]", !string.IsNullOrEmpty(common.LoadCommonCodeById(oNhanVien.GioiTinhID)) ? common.LoadCommonCodeById(oNhanVien.GioiTinhID) : str);
                strData = strData.Replace("[CMND]", !string.IsNullOrEmpty(oNhanVien.SoCMND) ? oNhanVien.SoCMND.ToString() : strDai);
                strData = strData.Replace("[QTCT]", ReturnTableData(pNhanVienId, "QTCT"));
                strData = strData.Replace("[PCCV]", ReturnTableData(pNhanVienId, "PCCV"));
                strData = strData.Replace("[PCK]", ReturnTableData(pNhanVienId, "PCK"));
                strData = strData.Replace("[HDLD]", ReturnTableData(pNhanVienId, "HDLD"));
                strData = strData.Replace("[NCC]", ReturnTableData(pNhanVienId, "NCC"));
            }
            return strData;
        }
    }
}
